<?php
/**
 * 
 * @author spring
 * @version 2014-6-7 上午10:46:49
 */
class  Pandianinout extends Basic {
	
   /**
    * 
    * Description 查询条件控制
    * @param field_type  bare_field_name
    * @param Kohana_Database_Query $pre
    * @param array $condition 查询条件
    * @param string $flag  为true就执行排序 
    * @param String $tablename 表名
    * @return Kohana_Database_Query 
    */
   public static function getListInfoCondition($pre,$condition,$flag=true,$tablename){
   	if(isset($condition['time'])&&!empty($condition['time'])){
   		$condition1=array('op_time','=',$condition['time']);
	    $pre=self::condition($pre,$condition1);
	    $pre=$pre->order_by('status','DESC' )->order_by('num', 'DESC');;
    }
    
   if(isset($condition['name'])&&!empty($condition['name'])){
     	    $user_id =Erpuser::lookup_by_nick(trim($condition['name']));
			$condition1=array('user_id','=',$user_id);
			$pre=self::condition($pre,$condition1);
	}
	
	if(isset($condition['sku'])&&!empty($condition['sku'])){
		$condition1=array('sku','=',strtoupper(trim($condition['sku'])));
		$pre=self::condition($pre,$condition1);
	}
	
	if(isset($condition['status'])&&!empty($condition['status'])){
		$condition1=array('status','=',$condition['status']);
		$pre=self::condition($pre,$condition1);
	}
	if(isset($condition['start_time'])&&!empty($condition['start_time'])){
			$condition1=array('pd_time','>=',$condition['start_time']);
			$pre=self::condition($pre,$condition1);
	}

	if(isset($condition['end_time'])&&!empty($condition['end_time'])){
			$time=date('Y-m-d', strtotime ("+1 day", strtotime($condition['end_time'])));
			$condition1=array('pd_time','<',$time);
			$pre=self::condition($pre,$condition1);
	}
    return $pre;
   }
   
   
}
